<template>
  <div class="process">
    <el-form label-width="120px" size="mini" class="form-view">
      <div id="module2">
        <div class="anthor-info-body">
          <PageableTable
            :columns="insideColumns"
            :loading="false"
            :table-height="240"
            :data="formItem.details"
            :disable-pageable="true"
            class="fixed-table-table"
          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
            />
            <el-table-column v-for="column in insideColumns" :key="column.key" :label="column.title" :prop="column.key" :sortable="column.sortable">
              <template slot-scope="scope">
                <column-render :render="column.render" :row="scope.row" :column="column" />
              </template>
            </el-table-column>
            <el-table-column label="转移后位置">
              <template slot-scope="scope">
                <treeselect
                  v-model="scope.row.zhuanyiLocation"
                  :multiple="false"
                  :options="availableLocations"
                  placeholder="请选择转移后位置"
                />
              </template>
            </el-table-column>
          </PageableTable>
        </div>
        <div style="text-align: right; margin-top:10px">
          <el-form-item>
            <el-button size="mini" @click="btnCancel">取 消</el-button>
            <el-button type="primary" @click="commit">签 收</el-button>
          </el-form-item>
        </div>
      </div>
    </el-form>
  </div>
</template>
<script>
import { confirmDetail as detail, confirmCreate as create } from '@neu/dcam-ui/api/zhuanyiKJ'
import PageableTable from '@neu/biz-core/components/PageableTable'
import { tree as locationTree } from '@neu/dcam-ui/api/location'
import treeselect from '@neu/biz-core/components/TreeSelect'
const formItem = {
  title: '',
  remark: '',
  workOrderNum: '',
  taskId: '',
  comprehensive: true,
  details: []
}
export default {
  components: {
    PageableTable,
    treeselect
  },
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      availableLocations: [],
      // 编辑的表单内容
      formItem: {
        ...formItem
      },
      insideColumns: [
        { title: '资产名称', width: 100, key: 'name' },
        { title: '资产编号', width: 120, key: 'code' },
        { title: '大分类', width: 100, key: 'bigTypeName' },
        { title: '中分类', width: 100, key: 'middleTypeName' },
        { title: '小分类', width: 100, key: 'smallTypeName' },
        { title: '规格型号', width: 100, key: 'specifications' },
        { title: '序列号', width: 100, key: 'serialnumber' },
        { title: '使用人', width: 100, key: 'managementUserName' }
      ]
    }
  },
  created() {
    this.fetch()
    // 位置树
    locationTree('kj').then(response => {
      this.availableLocations = response.data
    })
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
        })
      }
    },
    commit() {
      this.formItem.workOrderNum = this.workOrderNum
      this.formItem.taskId = this.taskId
      this.formItem.details.forEach(l => {
        const one = this.availableLocations.find(s => s.code === l.zhuanyiLocation)
        l.zhuanyiLocationName = one ? one.title : ''
      })
      // ge.x 2022-04-08 增加锁屏功能
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      create(this.formItem).then(res => {
        if (res.status === 'success') {
          loading.close()
          this.$emit('cancelNewOrderForm', 'refresh')
        }
      }).catch(() => {
        loading.close()
        this.$emit('cancelNewOrderForm', 'refresh')
      })
    },
    btnCancel() {
      this.$emit('cancelNewOrderForm', 'refresh')
    }
  }
}
</script>
<style lang="scss">
.process {
  .cell{
    overflow: unset !important;
  }
}
</style>
